package com.qianbei.user.login;

import android.content.Context;
import android.view.View;

import com.qianbei.R;
import com.qianbei.common.adapter.CommonAdapter;
import com.qianbei.common.adapter.ViewHolder;

import java.util.List;

/**
 * Created by user on 16/10/13.
 */

public class CountryCodeAdapter extends CommonAdapter<CountryCodeModel> {


    public CountryCodeAdapter(Context context, List<CountryCodeModel> data, int itemLayoutId) {
        super(context, data, itemLayoutId);
    }

    @Override
    public void convert(ViewHolder helper, CountryCodeModel item, int position) {

        if (position == getPositionForSection(item.getPinYin())){
            helper.setVisibility(R.id.tv_char, View.VISIBLE);
            helper.setText(R.id.tv_char,item.getPinYin());
        }else{
            helper.setVisibility(R.id.tv_char, View.GONE);
        }

        helper.setText(R.id.tv_country,mResources.getString(R.string.country_code_format,
                item.getCountry(),item.getCode()));

    }

    public int getPositionForSection(String  section) {
        if (section.equals("#")){
            return 0;
        }

        for (int i = 0; i < getCount(); i++) {
            if (section.equals(mDatas.get(i).getPinYin())) {
                return i;
            }
        }

        return -1;
    }

}
